package it.test.java.decoratord.pay.decorator;

import it.test.java.decoratord.pay.domain.Order;
import it.test.java.decoratord.pay.domain.OrderDetail;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Copyright 纳新智能科技有限公司
 * @Author Liky
 * @Date 2023/9/27
 */
public class BaseCount implements IBaseCount {
    @Override
    public BigDecimal getMoney(Order order) {
        BigDecimal money = BigDecimal.ZERO;
        List<OrderDetail> detailList = order.getOrderDetailList();
        if(detailList != null){
            for(OrderDetail detail : detailList){
                BigDecimal addMoney = detail.getNum().multiply(detail.getSku().getPrice());
                money = money.add(addMoney);
            }
        }
        order.setOrderMoney(money);
        System.out.println("订单应付金额为："+order.getOrderMoney());
        order.setPayMoney(money);
        System.out.println("订单实付金额为："+order.getPayMoney());
        return money;
    }
}
